package br.com.negocio;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.com.entidade.Funcionario;
import br.com.fachada.Fachada;
import br.com.logica.Logica;

public class AcessoEditarFuncionario implements Logica {

	@Override
	public void executa(HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		RequestDispatcher rd = null;

		String funcionarioID = request.getParameter("funcionarioID");

		HttpSession session = request.getSession();

		try {
			if(session.getAttribute("gerente_autenticado") != null) {
				long id = Long.parseLong(funcionarioID);
				Funcionario f = Fachada.getInstancia().buscarFuncionarioPorId(id);
				rd = request.getRequestDispatcher("editarFuncionario.jsp?id="+id+"&nome="+f.getNome()+"&cpf="+f.getCpf()+"&nivel="+f.getNivelDeAcesso());
				rd.forward(request, response);
			} else {
				rd = request.getRequestDispatcher("gerenciarFuncionario.jsp?msg=gerenteNaoAutorizado");
				rd.forward(request, response);
			}
		} catch (Exception e) {
			e.printStackTrace();
			rd = request.getRequestDispatcher("gerenciarFuncionario.jsp?msg=erroEditar");
			rd.forward(request, response);
		}

	}

}
